<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js类之属性示例</title>
</head>
<body>
  <script>
    const items = [
      { name: 'iphone', price: 8000 },
      { name: 'imac', price: 12000 },
      { name: 'ipad', price: 3688 }
    ]
    class Cart {
      constructor(model) {
        this.model = model
      }
      get name() {
        return this.model.name
      }
      get price() {
        return this.model.price
      }
      static create(data) {
        return data.map(item => new Cart(item))
      }
      static max(data) {
        return data.sort((a, b) => b.price - a.price)[0]
      }
      static total(data) {
        return data.reduce((res, item) => res += item.price, 0)
      }
    }
    const data = Cart.create(items)
    const max = Cart.max(data)
    const total = Cart.total(data)
    console.log(data)
    console.log(max)
    console.log(max.name)
    console.log(max.price)
    console.log(total)
  </script>
</body>
</html>